var app = getApp();
Page({
  data: {
  	order:{},
  	remark:null,
  	opens:0,
  	reasonlist:["不想要了","下单重复","地址有误","其他"],//原因
  	reasonindex:-1,
  },
  onLoad(options) {
  	var $th=this;
  	console.log(options.id)
  	app.globalAjax(
	  		'/api/order/detail',
	  		"get",
	  		{id:options.id},
	  		function(e){
	  			if(e.code==0)
	      	{
	      		$th.setData({
					      order: e.order
					  })
	      	}else{
	      		wx.showToast({
				        title: e.msg,
				        icon: "none"
				      });
	      	}
	  	})
  	
  },
  setopens:function(){//弹出
  	var $th=this;
  	var o=$th.data.opens?0:1;
		$th.setData({
  		opens:o
    });
  },
  selectref:function(e){//选择
  	var $th=this,
  			cur=e.currentTarget.dataset;
				$th.setData({
		  		reasonindex:cur.index
		    });
		    $th.setopens()
  },
  sub:function(e){
  	var that=this;
  	var formId = e.detail.formId;
  	if(that.data.reasonindex==-1){
  		wx.showToast({
				        title: "请选择退款原因",
				        icon: "none"});
  		return false;
  	}
  	var post={
	  	reason:that.data.reasonlist[that.data.reasonindex],//原因
	  	remark:that.data.remark,
	  	totalAmount:that.data.order.totalAmount,
	  	orderId:that.data.order.orderId,
	  	formId:formId
  	}
  	app.globalAjax(
	  		'/api/order/refund',
	  		"post",
	  		post,
	  		function(e){
	  			if(e.code==0)
	      	{
	      		var pages = getCurrentPages();//获取页面栈
						if (pages.length > 1) {
							//上一个页面实例对象
							var prePage = pages[pages.length - 2];
							//调用上一个页面的onShow方法
							prePage.onLoad()
						} 
						wx.navigateBack({delta: 1})
	      	}else{
	      		wx.showToast({
				        title: e.msg,
				        icon: "none"
				      });
	      	}
	  	})
  },inp:function(e){//监听输入
  	console.log(e.detail.value)
  	this.setData({
      remark: e.detail.value
    })
  }
})